﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using com.stockstar.baseinfo.datacontract;
using com.stockstar.baseinfo.datacontract.param;
using System.Web.Caching;

/// <summary>
/// Summary description for PubBean
/// </summary>
public class PubBean
{
    public static Dictionary<string, FundCode> AllFund;
    public PubBean()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static void getAllFund()
    {
        BaseInfoFundCom.FundCom fundcom = new BaseInfoFundCom.FundCom();
        ParamBase param = new ParamBase();
        param.fundtype = 0;
        param.investtype = -1;
        List<FundCode> codes = fundcom.GetFundCodeList(param);
        Dictionary<string, FundCode> tmpCode = new Dictionary<string, FundCode>();
        foreach (FundCode fund in codes)
        {
            try
            {
                tmpCode.Add(fund.Code, fund);
            }
            catch 
            {
                continue;
            }
        }
        AllFund = tmpCode;
    }

    public static Dictionary<string, FundCode> getAllFundExt()
    {
        string key = "FundCode-Dictionary";
        Dictionary<string, FundCode> tmpCode = HttpContext.Current.Cache.Get(key) as Dictionary<string, FundCode>;
        if (tmpCode == null || tmpCode.Count == 0)
        {
            tmpCode = new Dictionary<string, FundCode>();
            List<FundCode> codes = F10Query.GetFundCodeByTotal();
            foreach (FundCode fund in codes)
            {
                try
                {
                    tmpCode.Add(fund.Code, fund);
                }
                catch
                {
                    continue;
                }
            }
            if (tmpCode != null && tmpCode.Count > 0)
            {
                HttpContext.Current.Cache.Insert(key, tmpCode, null, DateTime.Now.AddHours(12), TimeSpan.Zero, CacheItemPriority.Normal, null);
            }
        }
        return tmpCode;
    }

    /// <summary>
    /// 基金吧地址
    /// </summary>
    /// <param name="fundcode">基金代码</param>
    /// <returns></returns>
    public static string getBarUrl(string fundcode)
    {
        string url = "http://bar.stockstar.com/redir1.asp?code=";
        url = url + fundcode.Trim();
        return url;
    }

    /// <summary>
    /// 基金走势地址
    /// </summary>
    /// <param name="fundcode">基金代码</param>
    /// <param name="type">目录层次，2表示二级目录</param>
    /// <returns></returns>
    public static string getFundZS(string fundcode,int type) 
    {
        if (type == 2)
        {
            //return "../f10/default.aspx?code=" + fundcode.Trim();
            return "/funds/" + fundcode.Trim() + ".shtml";
        }
        else
        {
            return "/funds/" + fundcode.Trim() + ".shtml";
        }
    }

    /// <summary>
    /// 基金净值地址
    /// </summary>
    /// <param name="fundcode">基金代码</param>
    /// <param name="type">目录层次，2表示二级目录</param>
    /// <returns></returns>
    public static string getFundJZ(string fundcode, int type) 
    {
        if (type == 2)
        {
            return "../f10/fundjz.aspx?code=" + fundcode.Trim();
        }
        else
        {
            return "/funds/f10/fundjz.aspx?code=" + fundcode.Trim();
        }
    }

    /// <summary>
    /// 股票地址
    /// </summary>
    /// <param name="stockcode">股票代码</param>
    /// <returns></returns>
    public static string getQuoteUrl(string stockcode) 
    {
        return "http://stock.quote.stockstar.com/" + stockcode.Trim() + ".shtml";
    }

    public static string getFundComUrl(string code, int type) 
    {
        if (type == 2)
        {
            return "../tab/fundgsxx.aspx?comcode=" + code;
        }
        else
        {
            return "/funds/tab/fundgsxx.aspx?comcode=" + code;
        }
    }

    /// <summary>
    /// 股票吧地址
    /// </summary>
    /// <param name="stockcode">股票代码</param>
    /// <returns></returns>
    public static string getQuoteBar(string quotecode) 
    {
        return "http://bar.stockstar.com/redir1.asp?code=" + quotecode.Trim();
    }

    public static string getNewsUrl(string quotecode) 
    {
        return "http://news.stockstar.com/info/dstock.htm?code=" + quotecode.Trim();
    }

    public static string getPics(int pictype, int picsize,string fundcode) 
    {
        string url = "/funds/fundimage/";//上线部署的时候切换为正式环境
        if (pictype == 1) 
        {
            url = url + "fundtzzh.aspx?fundcode=" + fundcode.Trim();
        }
        if (pictype == 2) 
        {
            url = url + "fundhytz.aspx?fundcode=" + fundcode.Trim();
        }
        if (pictype == 3) 
        {
            url = url + "fundzcpz.aspx?fundcode=" + fundcode.Trim();
        }
        if (picsize == 1) 
        {
            url += "&imgtype=smallchart";
        }
        if (picsize == 2) 
        {
            url += "&imgtype=bigchart";
        }
        return url;
    }

    public static string getPicsUrl(string fundcode,int width, int height,string chartName )
    {
        string url = "/funds/fundimage/fundDrawPic3D.aspx?";//上线部署的时候切换为正式环境
        url += "fundcode=" + fundcode + "&width=" + width + "&height=" + height + "&chartName=" + chartName;
        return url;
    }
}
